package pers.mobian.springseventh;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import pers.mobian.springfirst.sameBeanName.Cat;

/**
 * @Date 2021/7/18 17:04
 * @Created mobian
 * @Description
 */
public class MainTest3 {
	public static void main(String[] args) {

		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

		// 此处我们还是采用编程式的方式定义Bean，即第四种方式
		AbstractBeanDefinition definition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
		definition.setBeanClass(MoBian2.class);
		context.registerBeanDefinition("mobian",definition);


		context.refresh();
		// 获取getObject方法返回的对象
		System.out.println(context.getBean("mobian"));

		// 获取注册到Spring容器的beanDefinition的名字
		System.out.println(context.getBean("&mobian"));
	}
}
